<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
                    <script type="text/javascript" src="lib/html5shiv.js"></script>
                    <script type="text/javascript" src="lib/respond.min.js"></script>
                    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="./../lib/layui/css/layui.css">
    <!--[if IE 6]>
                    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
                    <script>DD_belatedPNG.fix('*');</script>
                    <![endif]-->
    <style>
        .sellOut i{
                                display: inline-block;
                                width: 14px;
                                height: 14px;
                                background: url("./../static/img/sellout.svg") no-repeat;background-size:contain;
                                vertical-align: middle;
                                line-height: 14px;
                            }
                        </style>
    <title>热销专区</title>
</head>

<body>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商品管理 <span
            class="c-gray en">&gt;</span>
        热销专区 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
            title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div>
            编号：
            <input type="text" class="input-text" style="width:150px" placeholder="输入商品编号" id="number" name="">
            商品类目：
            <select name="" class="input-text" id="autuStatus" style="width:15%;">
                <option value="">-请选择-</option>
            </select>
            状态：
            <select name="" class="input-text" id="status" style="width:10%;">
                <option value="">-请选择-</option>
                <option value="0">下架</option>
                <option value="1">上架</option>
            </select>
            <button type="submit" class="btn btn-success" name="" data-type="reload" id="search"><i class="Hui-iconfont">&#xe665;</i>
                搜索</button>
        </div>
        <table class="layui-hide" id="comList" lay-filter="comList"></table>
        <input type="" name="details_id" id="details_id" value="" style="display:none;" />
        <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript" src="./../static/js/common.js"></script>
        <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
        <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
        <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
        <script type="text/javascript" src="./../lib/layui/layui.js"></script>
        <script type="text/html" id="titleTpl">
            <a  title="编辑" lay-event="edit" class=""><i class="Hui-iconfont">&#xe6df;</i></a>
            <a  title="删除" lay-event="del" class=""><i class="Hui-iconfont">&#xe6e2;</i></a>
            {{#  if(d.top == 0){ }}
            <a  title="设置为首页展示" lay-event="setting-home" class=""><i class="Hui-iconfont">&#xe63c;</i></a>
            {{#  } else { }}
            <a  title="取消首页展示" lay-event="home" class=""><i class="Hui-iconfont">&#xe625;</i></a>
            {{#  } }}
        </script>
        <script>
            $(function () {
                partitionStatus('autuStatus')
            })
            layui.use('table', function () {
                var table = layui.table;
                var insTable = table.render({
                    elem: '#comList',
                    cellMinWidth: 80,
                    url: admin_url + '/kvmProductHot/productHotList',
                    // id为重置表格，进行搜索
                    id: 'reload',
                    request: {
                        pageName: 'page',
                        limitName: 'size'
                    },
                    // 传输模式
                    // contentType: 'application/json',
                    paresData: function (res) {
                        return {
                            'data': res.data
                        }
                    },
                    response: {
                        statusCode: 200
                    },
                    // // 传入数据
                    where: {
                        tokenUserId: userId,
                        token: token
                    },
                    // 回调
                    done: function (res, curr, count) {
                    },
                    method: 'post',
                    'page': 'true',
                    cols: [[
                        { checkbox: true, align: 'center' },
                        { field: 'productNo', title: '编号', align: 'center', width: 125 },
                        {
                            field: 'name', title: '商品名称', align: 'center', templet: function (obj) {
                                var name = '';
                                $.ajax({
                                    type: "post",
                                    xhrFields: { withCredentials: true },
                                    url: admin_url + '/kvmProduct/productByNo',
                                    async: false,
                                    data: { tokenUserId: userId, token: token, No: obj.productNo },
                                    success: function (data) {

                                        if (data.code == 200 && data.data != null) {
                                            name = '<span>' + data.data.name + '</span>'
                                        } else if (data.data == null) {
                                            name = '<span></span>'
                                            return name
                                        }
                                    }
                                })
                                return name
                            }
                        },
                        {
                            field: 'category', title: '商品分类', align: 'center', templet: function (obj) {
                                var category = '';
                                $.ajax({
                                    type: 'post',
                                    async: false,
                                    xhrFields: {
                                        withCredentials: true
                                    },
                                    url: admin_url + '/kvmProductPartition/productPartition',
                                    data: {
                                        tokenUserId: userId,
                                        token: token,
                                        id: obj.partitionId
                                    },
                                    success: function (data) {
                                        if (data.code == 200 && data.data != null) {
                                            return category = '<span>' + data.data.name + '</span>'

                                        }else {
                                            return category = '<span></span>'
                                        }
                                    }
                                })
                                return category
                            }
                        },
                        {
                            field: 'remark', title: '商品描述', align: 'center', templet: function (obj) {
                                var remark = '';
                                $.ajax({
                                    type: "post",
                                    xhrFields: { withCredentials: true },
                                    url: admin_url + '/kvmProduct/productByNo',
                                    async: false,
                                    data: { tokenUserId: userId, token: token, No: obj.productNo },
                                    success: function (data) {

                                        if (data.code == 200 && data.data != null && data.data.remark != null) {
                                            remark = '<span>' + data.data.remark + '</span>'
                                        } else if (data.data == null) {
                                            remark = '<span></span>'
                                        }
                                        return remark
                                    }
                                })
                                return remark
                            }
                        },
                        { field: 'createTime', title: '商品添加时间', align: 'center' },
                        { field: 'priceHot', title: '商品价格', align: 'center', templet: function (obj) {
                                var price = '';
                                $.ajax({
                                    type: "post",
                                    xhrFields: { withCredentials: true },
                                    url: admin_url + '/kvmProduct/productByNo',
                                    async: false,
                                    data: { tokenUserId: userId, token: token, No: obj.productNo },
                                    success: function (data) {

                                        if (data.code == 200 && data.data != null) {
                                            price = '<span>' + data.data.price + '</span>'
                                        } else if (data.data == null) {
                                            price = '<span></span>'
                                            return price
                                        }
                                    }
                                })
                                return price
                            } },
                        {
                            field: 'priceHot', title: '折扣价', align: 'center'
                        },
                        {
                            field: 'num', title: '库存', align: 'center', templet: function (obj) {
                                var currentStock = '';
                                $.ajax({
                                    type: "post",
                                    xhrFields: { withCredentials: true },
                                    url: admin_url + '/kvmProduct/productByNo',
                                    async: false,
                                    data: { tokenUserId: userId, token: token, No: obj.productNo },
                                    success: function (data) {

                                        if (data.code == 200 && data.data != null) {
                                            currentStock = '<span>' + data.data.currentStock + '</span>'
                                        } else if (data.data == null) {
                                            currentStock = '<span></span>'
                                        }else if(data.data.currentStock == 0){
                                            return '<span style = "color:#ff0000">售罄</span>'
                                        }
                                            return currentStock
                                    }
                                })
                                return currentStock
                            }
                        },
                        {
                            field: 'status', title: '状态', align: 'center', templet: function (obj) {
                                if (obj.status == 0) {
                                    return '<span class="layui-badge">下架</span>'
                                } else if (obj.status == 1) {
                                    return '<span class="layui-badge layui-bg-green" >上架</span>'
                                } else {
                                    return '<span></span>'
                                }
                            }
                        },
                        { toolbar: '#titleTpl', title: '操作', align: 'center' }
                    ]]
                })
                // 搜索功能 需要在标签上加载data-type = reload
                $('#search').on('click', function () {
                    var autuStatus = $("#autuStatus option:selected").val(),
                        productNo = $("#number").val(),
                        status = $("#status option:selected").val();
                    insTable.reload({
                        where: {
                            "token": token,
                            "tokenUserId": userId,
                            "productNo": productNo,
                            "status": status,
                            "partitionId": autuStatus
                        }, page: {
                        curr: 1
                    }
                    });
                });
                table.on('tool(comList)', function (obj) {
                    var data = obj.data;
                    var id = data.id;
                    if (obj.event == 'edit') {
                        var index = layer.open({
                            type: 2,
                            title: '编辑商品',
                            id: id,
                            content: './hot-edit.html'
                        })
                        layer.full(index);
                        $("#details_id").val(id)
                    } else if (obj.event === 'del') {
                        layer.confirm('是否删除该商品', function () {
                            $.ajax({
                                type: "post",
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmProductHot/delProductHot',
                                data: { tokenUserId: userId, token: token, id: id },
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('删除成功', {
                                            time: 1000,
                                            end: function () {
                                                // location.replace(location.href)
                                                $(".layui-laypage-btn").click();
                                            }
                                        })
                                    } else {
                                        layer.msg(data.msg)
                                    }
                                }
                            })
                        })
                    } else if (obj.event === 'setting-home') {
                        layer.confirm('是否设置为首页展示', { title: '设置首页展示' }, function () {
                            $.ajax({
                                type:'post',
                                xhrFields:{withCredentials:true},
                                url:admin_url + '/kvmProductHot/setHotPageTopShow',
                                data:{tokenUserId: userId, token: token, id:id},
                                success:function(data){
                                    if (data.code == 200) {
									layer.msg('设置成功', {
										time: 1000,
										end: function () {
                                            $(".layui-laypage-btn").click();
										}
									})
								} else {
									layer.msg(data.msg, {
										time: 1500
									})
								}
                                },error:function(data){
                                    layer.msg(data.msg)
                                }
                            })
                        })
                } else if (obj.event === 'home') {
                        layer.confirm('是否取消首页展示', { title: '取消首页展示' }, function () {
                            $.ajax({
                                type:'post',
                                xhrFields:{withCredentials:true},
                                url:admin_url + '/kvmProductHot/setHotPageTopHide',
                                data:{tokenUserId: userId, token: token, id:id},
                                success:function(data){
                                    if (data.code == 200) {
									layer.msg('取消成功', {
										time: 1000,
										end: function () {
										  $(".layui-laypage-btn").click();
										}
									})
								} else {
									layer.msg(data.msg, {
										time: 1500
									})
								}
                                },error:function(data){
                                    layer.msg(data.msg)
                                }
                            })
                        })
                }
                })
            })
        </script>
</body>

</html>